#pragma once

#include<iostream>

#define Die(code) do {exit(code); } while(0)
#define CONV(v) (struct sockaddr *)(v)

enum
{
    USAGE_ERR = 1,
    SOCKET_ERR,
    BIND_ERR,
    LISTEN_ERR
};

bool SplitString(const std::string &line, std::string *key, std::string *value, const std::string &sep)
{
    auto pos = line.find(sep);
    if(pos == std::string::npos) return false;
    *key = line.substr(0, pos);
    *value = line.substr(pos + sep.size());
    if(key->empty() || value->empty()) return false;
    return true;
}

//提取单行
bool ParseOneLine(std::string &request_str, std::string *out, const std::string &sep)
{   
    auto pos = request_str.find(sep);
    if(pos == std::string::npos)
        return false;
    *out = request_str.substr(0, pos);
    request_str.erase(0, pos + sep.size());
    return true;
}

//拆分属性行
bool SplitString(const std::string &header, const std::string &sep, std::string *key, std::string *value)
{
    auto pos = header.find(sep);
    if(pos == std::string::npos)
        return false;
    *key = header.substr(0, pos);
    *value = header.substr(pos+sep.size());
    return true;
}

const int gdefaultsockfd = -1;
const int gbacklog = 8;